package br.cin.stadium.middleware;

import java.util.ArrayList;

import br.cin.stadium.middleware.event.EventRemoteListener;
import br.cin.stadium.middleware.media.Media;
import br.cin.stadium.middleware.media.MediaReference;

/**
 * Represents a Tuple Space Middleware used to Sports application allow users/devices video exchanged.
 * Using this Interface its possible to access all middleware functionalities.
 * 
 * @author Fabiano, Jorge, Rafael and Vando
 */
public interface StadiumTupleSpace {
	
	
	/**
	 * publish a media and stadiumSection into tuple space
	 * 
	 * @param media A media that will be written in the StadiumSpace
	 * @return True if success, otherwise false 
	 * @throws StadiumException 
	 */
	public boolean write(Media media) throws StadiumException ;
	
	/**
	 * Read all mediaReferences from tuple space.
	 * 
	 * @return An ArrayList with MediaReference as its content
	 * @throws StadiumException 
	 */
	public ArrayList<MediaReference> readAll() throws StadiumException ;
	
	/**
	 * Read mediaReference from tuple space that matches with stadium sector parameter.
	 * 
	 * @param stadiumSection integer that represents stadium sector 
	 * @return An ArrayList with MediaReference as its content
	 * @throws StadiumException 
	 */
	public ArrayList<MediaReference> read(int stadiumSection) throws StadiumException ;
	
	/**
	 * Read mediaReference from tuple space that matches with name parameter.
	 * 
	 * @param mediaName String that represents media name
	 * @return An ArrayList with MediaReference as its content
	 * @throws StadiumException 
	 */
	public ArrayList<MediaReference> read(String mediaName) throws StadiumException ;
	
	/**
	 * Request Media with its content - Client calls this method when desires to watch a media/video.
	 * 
	 * @param mediaReference A MediaReference - represents device that contains the media. 
	 * @return Media with all data
	 */
	public Media requestMedia(MediaReference mediaReference) throws StadiumException ;
	
	/**
	 * Get a Media making a lock in Space Object
	 */
	public void take();
	
	/**
	 * Notify all devices listeners about a Media change.
	 */
	public void notifyMediaChanges(EventRemoteListener listener, int sector);
	
	/**
	 * Unregister the Unit into the StadiumDirectory
	 * @throws StadiumException 
	 */
	public void unRegisterUnit() throws StadiumException;
}
